<?php
use app\common\enum\order\PayStatus as PayStatusEnum;
?>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">大额充值订单</div>
                </div>

                <input type="text" id="order_no"  class="tpl-form-input"  readonly style="display: none;">

                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form id="form-search" class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <div class="am-u-sm-12 am-u-md-3" style="width:35%">
                                <div class="am-form-group" style="max-width:initial">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <i class="iconfont am-margin-right-xs">总额度：<?= $edu['money'] ?>  元</i>
                                        </div>

                                        <div class="am-btn-group am-btn-group-xs"  id="chongzhi">
                                            <a class="am-btn am-btn-success am-radius"
                                               href="javascript:void(0);">
                                                <i class="iconfont am-margin-right-xs">充值</i>
                                            </a>
                                        </div> 
                                        <div class="am-btn-group am-btn-group-xs" id="tixian">
                                            <a class="am-btn am-btn-success am-radius">
                                                <i class="iconfont am-margin-right-xs" >提现 </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9" style="float: right;width:65%">
                                <div class="am fr">
                                    <div class="am fr">
                                        <div class="am-form-group am-fl">
                                            <?php $payStatus = $request->get('pay_status'); ?>
                                            <select name="pay_status"
                                                    data-am-selected="{btnSize: 'sm', placeholder: '支付状态'}">
                                                <option value=""></option>
                                                <option value="-1"
                                                    <?= $payStatus === '-1' ? 'selected' : '' ?>>全部
                                                </option>
                                                <?php foreach (PayStatusEnum::data() as $item): ?>
                                                    <option value="<?= $item['value'] ?>"
                                                        <?= $item['value'] == $payStatus ? 'selected' : '' ?>><?= $item['name'] ?>
                                                    </option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                        <div class="am-form-group tpl-form-border-form am-fl">
                                            <input type="text" name="start_time"
                                                   class="am-form-field"
                                                   value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                                   data-am-datepicker readonly>
                                        </div>
                                        <div class="am-form-group tpl-form-border-form am-fl">
                                            <input type="text" name="end_time"
                                                   class="am-form-field"
                                                   value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                                   data-am-datepicker readonly>
                                        </div>
                                        <div class="am-form-group am-fl">
                                            <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                                <input type="text" class="am-form-field" name="search"
                                                       placeholder="请输入订单号" value="<?= $request->get('search') ?>">
                                                <div class="am-input-group-btn">
                                                    <button class="am-btn am-btn-default am-icon-search"
                                                            type="submit"></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%" class="am-table am-table-centered
                        am-text-nowrap am-margin-bottom-xs">
                            <thead>
                            <tr>
                                <th width="5%">订单id</th>
                                <th width="7%">订单号</th>
                                <th width="7%">实际支付金额</th>
                                <th width="7%">额度金额</th>
                                <th width="7%">支付状态</th>
                                <th width="7%">订单创建时间</th>
                                <th width="7%">支付时间</th>
                                <th width="7%">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['order_id'] ?></td>
                                    <td class="am-text-middle"><?= $item['order_no'] ?></td>
                                    <td class="am-text-middle"><?= $item['pay_price'] ?></td>
                                    <td class="am-text-middle"><?= $item['recharge_money'] ?></td>
                                    <td class="am-text-middle"><?php if ($item['pay_status'] ==10) : ?>
                                            <span class="x-color-green">待付款</span>
                                        <?php elseif($item['pay_status'] ==20): ?>
                                            <span class="x-color-red">已付款</span>
                                        <?php endif; ?>
                                    </td> 

                                    <td class="am-text-middle"><?= format_time((int)$item['create_time'])?></td>
                                    <?php if($item['pay_time']!=0):?>
                                    <td class="am-text-middle"><?= format_time((int)$item['pay_time'])?></td>
                                    <?php else:?>
                                    <td class="am-text-middle">---</td>
                                    <?php endif;?>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if ($item['is_delete'] ==0) : ?>
                                                <a onclick=delInfo('<?=$item['order_id']?>') class="j-delete"
                                                   data-id="<?= $item['order_id'] ?>">
                                                    <i class=""></i> 删除
                                                </a>
                                            <?php elseif($item['is_delete'] ==1): ?>
                                                <span class="x-color-red">已删除</span>
                                            <?php endif; ?>
                                        </div>
                                    </td>

                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
<script>
    $(function () {
        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('finance.order/goodsExport') ?>" + '&' + $.urlEncode(data);
        });
    });

    //删除
    function delInfo(order_id){
        $.ajax({
            url:"index.php?s=/store/finance.order/delLarge",
            dataType:"json",
            async:true,
            data:{"order_id":order_id},
            type:"post",
            success:function(req){
                if(req.code==1){
                    $.show_success(req.msg);
                    window.location = "<?= url('finance.order/large') ?>";
                }else{
                    $.show_error(req.msg);
                }
            },
            error:function(){

            }
        });
    }
    //提现
    $('#tixian').click(function(){
        layer.prompt({title: '申请提现', formType:0,placeholder:'请输入提现额度金额'}, function(money, index){
            if (isNaN(money)) {
                $.show_error("请输入数字！");
                return;
            }
            $.ajax({
                url:"index.php?s=/store/finance.order/apply",
                dataType:"json",
                async:true,
                data:{"money":money},
                type:"post",
                success:function(req){
                    if(req.code==1){
                        $.show_success(req.msg);
                        window.location = "<?= url('finance.order/applyindex') ?>";
                    }else{
                        $.show_error(req.msg);
                    }
                },
                error:function(){

                }
            });
            layer.close(index);
        });
    })
    //充值
    $('#chongzhi').click(function(){
        layer.prompt({title: '充值', formType:0,placeholder:'请输入充值额度金额'}, function(money, index){
            if (isNaN(money)) {
                $.show_error("请输入数字");
                return;
            }
            $.ajax({
                url:"index.php?s=/store/finance.large/preparePay",
                dataType:"json",
                async:true,
                data:{"recharge_money":money},
                type:"post",
                success:function(req){
                    if(req.code==1){
                        $("#order_no").val(req.data.order_no);//赋值
                        var html="<img style='height: 280px;width: 280px;' src='index.php?s=/store/finance.large/getQrcode&url="+req.data.url+"'>";
                        layer.open({
                            type : 1,
                            title : ['您本次充值需要支付'+money/100+'元','color:#fff;background-color:#01AAED;'],
                            closeBtn : 0,
                            shade: [0.7, '#393D49'],
                            area : '280px',
                            skin : 'layui-layer-nobg', //沒有背景色
                            shadeClose : true,
                            content : html
                        });

                        var numb = 1;
                        var time = setInterval(function () {
                            numb++;
                            var order_no = $("#order_no").val();

                            $.post("<?= url('finance.large/checkPay') ?>"
                                , {
                                    order_no: order_no,
                                }
                                , function (result) {
                                    if(result.code === 1){
                                        clearInterval(time);
                                        $.show_success(result.msg);
                                        location.href = "<?= url('finance.order/large') ?>";
                                    }
                                });

                            if(numb>120){
                                clearInterval(time);
                                return false;
                            }
                        },6000)

                    }else{
                        $.show_error(req.msg);
                    }
                },
                error:function(){

                }
            });

        });
    })



</script>


